<?php
namespace Admin\Controller;
use Admin\Controller\CommonController;
/**
* 专门用于esayui combobox异步加载数据
* @date: 2017年8月1日 下午4:54:24
*/
class ComboBoxController extends CommonController {
    
    /**
    * 城市combobox
    * @date: 2017年8月1日 下午4:55:30
    
    public function city(){
        $enum = I('request.province',5500);
        $cascadedata = M('cascadedata');
        $map = array();
        $map['datagroup'] = 'area';
        $map['level'] = 1;
        $map['datavalue']  = array('between',array((int)($enum),$enum+500));
        
        $rows = $cascadedata->where($map)->order('orderid ASC,datavalue ASC')->select();
        $result = array();
        foreach($rows as $row){
            $single = array();
            $single['id'] = $row['id'];
            $single['dataname'] = $row['dataname'];
            $single['datavalue'] = $row['datavalue'];
            array_push($result, $single);
        }
        $this->ajaxReturn($result);
        //$this->display('School/index');
    }*/
    
    /**
    * 级联通用方法
    * @date: 2017年8月1日 下午4:55:30
    */
    public function cascade(){
        $cascadedata = M('cascadedata');
        $map = array();
        $map['datagroup'] = I('request.datagroup','area');
        $map['level'] = I('request.level',0);
        
        $rows = $cascadedata->where($map)->field('id,dataname,datavalue')->order('orderid asc,datavalue ASC')->select();
        $this->ajaxReturn($rows);
        
    }
    
    public function cascadeInline(){
        
        $datagroup = I('request.datagroup','area');
        $level = (int)(I('request.level',0));
        $enum = (int)(I('request.enum',''));
        $interval = I('request.interval','');
        
        $cascadedata = M('cascadedata');
        $map = array();
        $map['datagroup'] = $datagroup;
        $map['level'] = $level;
        if(!empty($enum)){
            $map['datavalue']  = array('between',array($enum,$enum+$interval));
        }
        
        $rows = $cascadedata->where($map)->field('id,dataname,datavalue')->order('orderid ASC,datavalue ASC')->select();
        $this->ajaxReturn($rows);
    }
    
}